package com.jeff.tianti.cms.service;

import com.jeff.tianti.cms.dto.font.PageBeanUid;
import com.jeff.tianti.cms.entity.ColumnInfo;
import com.jeff.tianti.cms.entity.ConsultCategory;
import com.jeff.tianti.cms.dao.ConsultCategoryDao;
import com.jeff.tianti.cms.dto.ConsultCategoryQueryDTO;
import com.jeff.tianti.common.service.CommonService;
import com.jeff.tianti.common.entity.PageModel;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
/**
 * @author liuyi
 * @desc ConsultCategoryService类 
 * @date 2019-06-28
 */
@Service
public class ConsultCategoryService extends CommonService< ConsultCategory,String >  {

    @Autowired
    private ConsultCategoryDao consultCategoryDao;

    @Autowired
    public void setConsultCategoryDao(ConsultCategoryDao consultCategoryDao){
      super.setCommonDao(consultCategoryDao);
    }

    public PageModel<ConsultCategory> queryConsultCategoryPage(ConsultCategoryQueryDTO consultCategoryQueryDTO){
           return this.consultCategoryDao.queryConsultCategoryPage(consultCategoryQueryDTO);
    }

    public List<ConsultCategory> queryConsultCategoryList(ConsultCategoryQueryDTO consultCategoryQueryDTO){
           return this.consultCategoryDao.queryConsultCategoryList(consultCategoryQueryDTO);
    }

    @Autowired
    private ColumnInfoService columnInfoService;

    public Map findAllNoDel() {
        List<ConsultCategory> list = consultCategoryDao.findAllNoDel();
        Map<String, List<ConsultCategory>> map = list.stream().collect(Collectors.groupingBy(ConsultCategory::getCmsId));
        Set<String> set = map.keySet();
        Map<String, Object> newMap = new HashMap<>();
        set.stream().forEach(t ->{
            ColumnInfo con = columnInfoService.find(t);
            newMap.put(con.getName()+","+con.getId(), map.get(t));
        });
        return newMap;
    }


    public List<ConsultCategory> findConsultCategoryById(String id) {
        return consultCategoryDao.findConsultCategoryById(id);
    }

}